<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul,
        ol {
            list-style: none;
        }
        
    </style>
</head>

<body>
    <form action="" id="form">
        <input type="text"><br>
        <input type="text"><br>
        <input type="text"><br>
        <input type="text"><br>
        <input type="text"><br>
        <input type="text">
    </form>
    <script>
        var form = document.getElementById("form")

        form.onclick = function (e) {
            for (var i = 0; i < form.children.length; i++) {
                form.children[i].style.backgroundColor = ""
            }
            e.target.style.backgroundColor = "gray"
            e.currentTarget.style.backgroundColor = ""
        }
    </script>

</body>

</html>